<?php

class SiteController extends Controller
{
	/**
	 * Displays the login page
	 */
	public function actionLogin()
	{
		$model=new LoginForm;

		// collect user input data
		if(isset($_POST['LoginForm']))
		{
			$model->username = $_POST['LoginForm']['username'];
			$model->password = $_POST['LoginForm']['password'];
			
			// validate user input and redirect to the previous page if valid
			if($model->login())
			{
				$this->redirect(Yii::app()->user->returnUrl);
			}
			else 
				echo '失败';
		}
		// display the login form
		//$this->render('login',array('model'=>$model));
		$this->renderPartial('login',array('model'=>$model));
	}

	/**
	 * Logs out the current user and redirect to homepage.
	 */
	public function actionLogout()
	{
		Yii::app()->user->logout();
		$this->redirect(Yii::app()->homeUrl);
	}
}